var canvas = document.createElement('canvas');
var chart_map = echarts.init(canvas, 'macarons', {width: 4096, height:2048, renderer: 'canvas'});
var chart_left = echarts.init(
        document.getElementById('left'), 'macarons', {renderer: 'canvas'});

var chart_right2 = echarts.init(document.getElementById('right2'), 'macarons', {renderer: 'canvas'});
var chart_right1 = echarts.init(document.getElementById('right1'), 'macarons', {renderer: 'canvas'});
$(
	function () {
		fetchData(chart_left, chart_right1, chart_right2);
		/*设置与后台同步数据的间隔*/
		setInterval(fetchData, 1000 * 60 * 30);
	}
);
//关于地图的option
var options_of_map = {
   "globe": {
   "show": true,
   "baseTexture":chart_map,
   shading: 'lambert',
    light: {
        ambient: {
            intensity: 0.6
        },
        main: {
            intensity: 0.2
        }
     }
   }};
//更新后台的covchart对象
function updateDate(){
   $.ajax({
		type: "GET",
		url: "/updateWorldData",
		dataType: "json",
		success: function (result) {
            console.log(result);
		}
	});
}
//所有需要更新图表的ajax都在这个函数里
function fetchData(){
    updateDate();

	$.ajax({
		type: "GET",
		url: "/worldCloud",
		dataType: "json",
		success: function (result) {
			chart_right2.setOption(result);
		}
	});

	$.ajax({
		type: "GET",
		url: "/worldBar",
		dataType: "json",
		success: function (result) {
			chart_right1.setOption(result);
		}
	});

	$.ajax({
		type: "GET",
		url: "/worldMap",
		dataType: "json",
		success: function (result) {
		 chart_map.setOption(result);
         chart_left.setOption(options_of_map);
		}
	});

    $.ajax({
        type: "GET",
        url: "/worldData",
        dataType: "json",
        success: function (result) {
            $("#currentConfirmedCount").html(result.currentConfirmedCount);
            $("#confirmedCount").html(result.confirmedCount);
            $("#deadCount").html(result.deadCount);
            $("#deathRate").html(result.deathRate+'%');
        }
    });
}